<% include header %>
    <div class="container">
        <form class="form create" method="post">
            <div>
                <label>用户名:</label>
                <input class="input" placeholder="用户名" type="text" name="name">
            </div>
            <div>
                <label>密码:</label>
                <input placeholder="密码" class="input" type="password" name="password">
            </div>
            <div class="submit">登录</div>
        </form>
    </div>
    <script type="text/javascript">
        $('.submit').click(() => {
            console.log('ssds' + $('.form').serialize());
            $.ajax({
                url: '/signin',
                type: 'post',
                data: $('.form').serialize(),
                cache: false,
                dataType: 'json',
                success: function(msg) {
                    if (!msg) {
                        $('.error').text('用户名或密码错误');
                        $('input').val('');
                        fade('.error');
                    } else {
                        $('.success').text('登录成功');
                        fade('.success');
                        var str = $('.form').serializeArray()
                        if (str[0].value != 'admin') {
                            setTimeout(() => {
                                window.location.href = '/posts';
                            }, 1000);
                            console.log(str[0].value);
                        } else {
                            setTimeout(() => {
                                window.location.href = '/adminpost';
                            }, 1000);
                            //   console.log('ssds' + $('.form').serialize());
                        }


                    }
                },
                error: function() {
                    alert('登录发生异常');
                }
            });

        });
    </script>
    <% include footer %>